{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "c8416453",
   "metadata": {},
   "outputs": [],
   "source": [
    "import sqlite3\n",
    "\n",
    "# 连接到SQLite数据库\n",
    "conn = sqlite3.connect('company_database.db')\n",
    "cursor = conn.cursor()\n",
    "\n",
    "# 创建企业表，母公司和子公司在一张表里\n",
    "cursor.execute('''\n",
    "CREATE TABLE IF NOT EXISTS companies (\n",
    "    company_id INTEGER PRIMARY KEY AUTOINCREMENT,\n",
    "    company_name TEXT NOT NULL,\n",
    "    social_credit_code TEXT,\n",
    "    company_type TEXT,\n",
    "    national_standard_industry TEXT,\n",
    "    registered_address TEXT,\n",
    "    longitude REAL,\n",
    "    latitude REAL,\n",
    "    parent_company_id INTEGER,\n",
    "    trademark_id INTEGER,\n",
    "    FOREIGN KEY (parent_company_id) REFERENCES companies(company_id)\n",
    "    FOREIGN KEY (trademark_id) REFERENCES trademarks(id)\n",
    ")\n",
    "''')\n",
    "\n",
    "# 创建生产地址表\n",
    "cursor.execute('''\n",
    "CREATE TABLE IF NOT EXISTS production_addresses (\n",
    "    id INTEGER PRIMARY KEY AUTOINCREMENT,\n",
    "    address TEXT,\n",
    "    longitude REAL,\n",
    "    latitude REAL,\n",
    "    company_id INTEGER,\n",
    "    FOREIGN KEY (company_id) REFERENCES companies(company_id)\n",
    ")\n",
    "''')\n",
    "\n",
    "# 创建产品商标表\n",
    "cursor.execute('''\n",
    "CREATE TABLE IF NOT EXISTS trademarks (\n",
    "    id INTEGER PRIMARY KEY AUTOINCREMENT,\n",
    "    trademark_name TEXT,\n",
    "    data BLOB\n",
    ")\n",
    "''')\n",
    "\n",
    "# 提交更改并关闭连接\n",
    "conn.commit()\n",
    "conn.close()\n",
    "    "
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "langchain",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.21"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
